import os
import datetime
import mrkt
from wxauto import WeChat

today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)

os.chdir(r'D:\lz\每日空调')
if os.path.exists(str(yesterday)) and len(os.listdir(str(yesterday))) == 24:
    os.system(f"tar -cvf {yesterday}.rar {yesterday}")

else:
    mrkt.main()
    os.system(f"tar -cvf {yesterday}.rar {yesterday}")
try:
    wx = WeChat()
    # 发送空调数据
    files = f'{yesterday}.rar'
    who = '易方达项目日常维护群'
    wx.SendFiles(filepath=files, who=who)
    # 发送消息给易方达项目日常维护群
    msg = f'{yesterday}空调数据已发送'
    wx.SendMsg(msg=msg, who=who)
    os.remove(files)
except Exception as e:
    print('发送微信失败', e)
